package com.ustze.ocr.domain.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author zongun
 * @TableName biz_day_dispatch_statistic
 * @date 2024/01/25
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DispatchPushVo {



    /**
     * 工作面名称
     */
    private String workSurfaceName;


    /**
     * 班次
     */
    private DispatchNumberVo dispatch1;
    /**
     *
     */
    private DispatchNumberVo dispatch2;
    /**
     *
     */
    private DispatchNumberVo dispatch3;
    /**
     *
     */
    private DispatchNumberVo dispatch4;




    public static DispatchPushVo buildVo(DayDispatch dispatch, List<WorkSurface> workSurfaces) {
        AtomicReference<String> faceName = new AtomicReference<>();
        AtomicBoolean four = new AtomicBoolean(false);
        workSurfaces.stream().filter(face -> face.getId().equals(dispatch.getWorkSurfaceId())).findFirst().ifPresent(face ->{
            faceName.set(face.getWorkSurfaceName());
            four.set(null != face.getFixedShift() && 2 == face.getFixedShift());
        });
        return DispatchPushVo.builder()
            .workSurfaceName(faceName.get())
            .dispatch1(DispatchNumberVo.builder()
                .circTime(dispatch.getCircTime1())
                .circMetre(dispatch.getCircMetre1())
                .remark(dispatch.getRemark1())
                .build())
            .dispatch2(DispatchNumberVo.builder()
                .circTime(dispatch.getCircTime2())
                .circMetre(dispatch.getCircMetre2())
                .remark(dispatch.getRemark2())
                .build())
            .dispatch3(DispatchNumberVo.builder()
                .circTime(dispatch.getCircTime3())
                .circMetre(dispatch.getCircMetre3())
                .remark(dispatch.getRemark3())
                .build())
            .dispatch4(four.get() ? DispatchNumberVo.builder()
                .circTime(dispatch.getCircTime4())
                .circMetre(dispatch.getCircMetre4())
                .remark(dispatch.getRemark4())
                .build() : null)
            .build();
    }


}
